package com.example.myapplication;

import android.support.design.widget.CollapsingToolbarLayout;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;

import com.example.myapplication.adapter.MyViewPagerAdapter;
import com.example.myapplication.fragment.TeacherOtherFragment;
import com.example.myapplication.fragment.TeacherOwnFragment;

public class WorkInfoActivity extends AppCompatActivity {
    private ViewPager viewPager;
    private TeacherOwnFragment teacherOwnFragment;
    private FragmentManager fragmentManager;
    private MyViewPagerAdapter myViewPagerAdapter;
    private TeacherOtherFragment teacherOtherFragment;
    private TabLayout tabLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_work_info);
        initContentView();
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        teacherOwnFragment = new TeacherOwnFragment();
        teacherOtherFragment = new TeacherOtherFragment();
        if (viewPager!= null) {
            setupViewPager();
        }

        tabLayout.setupWithViewPager(viewPager);

    }

    private void setupViewPager() {
        MyViewPagerAdapter myViewPagerAdapter = new MyViewPagerAdapter(getSupportFragmentManager());
        myViewPagerAdapter.addFragment(teacherOwnFragment, "自己");
        myViewPagerAdapter.addFragment(teacherOtherFragment,"他人");
        viewPager.setAdapter(myViewPagerAdapter);
    }

    private void initContentView() {

        viewPager = (ViewPager) findViewById(R.id.viewpager);
        tabLayout = (TabLayout) findViewById(R.id.tabs);

    }
}
